<template>
  <view class="home">
    <div class="duihuanma">
      <uni-card :is-shadow="false">
        <view class="uni-common-mt">
          <view class="uni-form-item uni-column">
            <view class="title">兑换码</view>
            <input
              class="uni-input"
              v-model="duihuanmaval"
              focus
              placeholder="请输入兑换码"
            />
          </view>
          <button
            type="primary"
            @click="duihuan"
            style="
              height: 25px;
              line-height: 25px;
              font-size: 14px;
              margin-top: 10px;
            "
          >
            提交
          </button>
        </view>
      </uni-card>
    </div>
  </view>
</template>

<script lang="ts" setup>
import { postcollectcode } from "@/api";
import { ref } from "vue";

const duihuanmaval = ref("");
const duihuan = async () => {
  await postcollectcode(duihuanmaval.value)
    .then((res) => {
      if (res == null || res == "null") {
        uni.$u.toast("兑换成功");
      } else {
        uni.$u.toast(res.msg);
      }
    })
    .catch((orr) => {
      console.log(orr);
      console.log("=================");
      uni.$u.toast(orr);
    });
  /* let res = await postcollectcode(duihuanmaval.value);
  console.log(res);
  if (res == null || res == "null") {
    uni.$u.toast("兑换成功");
  } else {
    uni.$u.toast(res.msg);
  } */
};
</script>

<style lang="scss">
.home {
  width: 100%;
  height: 100vh;
}

.duihuanma {
  width: 100%;
  height: 300px;
}
</style>